package top.yqingyu.trans$client.main;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.yqingyu.qymsg.QyMsg;

/**
 * @author YYJ
 * @version 1.0.0
 * @ClassName top.yqingyu.trans$client.main.RcvQueueToContainer
 * @description
 * @createTime 2023年02月15日 01:05:00
 */
public class RcvQueueToContainer implements Runnable {


    private final TransClient client;
    private final static Logger logger = LoggerFactory.getLogger(PrintMsgThread.class);

    private RcvQueueToContainer(TransClient client) {
        this.client = client;
    }

    public static void init(TransClient client) {
        Thread th = new Thread(new RcvQueueToContainer(client));
        th.setDaemon(true);
        th.setName("RcvQueueToContainer");
        th.start();
    }

    @Override
    public void run() {
        while (client.running.get()) {
            QyMsg msg = null;
            try {
                msg = client.RSP_MSG_QUEUE.take();
                String msgId = msg.gainMsgId();
                client.RCV_MSG_CONTAINER.put(msgId, msg);
            } catch (Exception e) {
                logger.error("{}", msg, e);
            }
        }
    }
}
